"""
未输入账户
"""
import pytest
from Config.Base import Base
from playwright.sync_api import Page, expect, Playwright
from Config.config import *
from Config.URL import *
import allure, os
from Config.Base import Base
from Config.Tool import tool

# 测试用例数据
case_data = {'module': '用户管理', 'caseid': '未输入账户',
             'name': '张三张三张三张三张三张三张三张三张三张三张三张三张三',
             'account': 'zhangsanzhangsanzhangsanzhangsanzhangsanzhangsanzhangsanzhangsan'}


@pytest.mark.基础管理系统
@pytest.mark.组织管理
@allure.step(case_data['caseid'])
# @pytest.mark.parametrize('case', case_data)
def test_case(playwright : Playwright) -> None:
    # 测试结果标题
    allure.dynamic.feature(case_data['module'])
    allure.dynamic.title(case_data['caseid'])
    allure.dynamic.suite(case_data['caseid'])

    SetupTeardown = Base(playwright)
    SetupTeardown.goto(url)
    SetupTeardown.login(username_admin, password_admin)
    context = SetupTeardown.context
    page = SetupTeardown.page
    page.wait_for_timeout(2000)

    page.goto(url + url_yonghuguanli)
    page.wait_for_timeout(2000)
    page.get_by_text("账号姓名查询清空").click()
    page.get_by_role("tree").get_by_text("环北部湾广西水资源配置有限公司").click()
    page.get_by_role("button", name=" 新建").click()
    page.get_by_placeholder("请输入账户").fill(case_data['account'])
    page.locator("form").filter(has_text="基础信息账户 64/200 姓名 0/200").get_by_placeholder("请输入姓名").fill(
        case_data['name'])
    page.get_by_role("button", name="确 定").click()
    # 断言
    expect(page.get_by_role("paragraph")).to_contain_text(" 姓名不能超过15个字符 账户不能超过15个字符")
    # 测试结果截图
    filename = os.path.join(test_screenshot_dir, f"{case_data['caseid']}.png")
    page.screenshot(path=filename)
    allure.attach.file(source=filename, name=case_data['caseid'],
                       attachment_type=allure.attachment_type.PNG)

    SetupTeardown.close()
